<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>04练习3_函数</title>
</head>

<body>
	<h1>简易计算器</h1>
	<input type="text" id="one" placeholder="请输入第一个数">
	<select id="symbol">
		<option value="+">+</option>
		<option value="-">-</option>
		<option value="*">*</option>
		<option value="/">/</option>
	</select>
	<input type="text" id="two" placeholder="请输入第二个数">
	<button id="btn">=</button>
	<span id="result"></span>
</body>
<script>
	// 编写一个函数，计算两个数字的和、差、积、商  calc(num1,num1,type)   

	var btn = document.getElementById('btn')
	var result = document.getElementById('result')

	btn.onclick = function () {
		var num1 = document.getElementById('one').value - 0
		var num2 = document.getElementById('two').value - 0
		var type = document.getElementById('symbol').value
		res = calc(num1, num2, type)
		result.innerText = `${res}`
	}

	function calc(a, b, type) {
		switch (type) {
			case '+': return a + b;
			case '/': return a / b;
			case '*': return a * b;
			case '-': return a - b;
		}
	}




</script>

</html>